package com.lyj.linearalgebra.comment.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.lyj.linearalgebra.comment.domain.Comment;
import com.lyj.linearalgebra.comment.domain.Comments;

import cn.itcast.jdbc.TxQueryRunner;

public class CommentDao {
	
	private QueryRunner qr = new TxQueryRunner();

	public List<Comments> findAll(String pid) {
		
		try {
			String sql = "select * from comments where pid=? order by commenttime";
			return qr.query(sql, new BeanListHandler<Comments>(Comments.class),pid);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	public void addComment(Comment form) {
		try {
			String sql = "insert into comment values(?,?,?,?,?)";
			Object[] params = {form.getCid(),form.getUid(),
				form.getPid(),form.getContent(),form.getTime()};
			qr.update(sql, params);
		} catch (SQLException e) {
            throw new RuntimeException(e);
		}
	}


}
